<template>
  <div class="app-container">
    <div class="backgroundClass">
      <!-- 试题搜索 -->
      <el-page-header
        style="margin-bottom: 24px"
        @back="
          () => {
            this.$router.go(-1);
          }
        "
        content="试题搜索"
      >
      </el-page-header>
      <div style="width: 100%; display: flex; justify-content: flex-end">
        <el-input v-model="keyword" placeholder="请输入关键词">
          <el-button slot="append" @click="search" type="primary">
            搜索
          </el-button>
        </el-input>
      </div>
      <p style="text-align: right; color: red">
        注：请从题干第一个字符开始输入查询
      </p>
      <div
        style="height: calc(100vh - 218px); overflow: auto; margin-top: 10px"
      >
        <van-empty description="内容为空" v-if="list.length == 0" />
        <div v-for="(item, index) in list" :key="index">
          <span
            style="
              display: inline-block;
              width: 98%;
              font-size: 26px;
              margin-bottom: 20px;
            "
            >{{ item.name }}、{{ item.stem }}</span
          >
          <el-radio-group
            v-model="item.daan"
            class="radio-group-box"
            v-if="item.qtype == '单选'"
            disabled="disabled"
          >
            <div
              class="radio_box"
              v-for="(item, index) in item.tiList"
              :key="index"
            >
              <el-radio :label="item.cred" v-if="item.content"
                >{{ item.cred }} {{ item.content }}</el-radio
              >
              <el-radio :label="item.cred" v-if="item.content_img"
                >{{ item.cred }} {{ item.content_img }}</el-radio
              >
            </div>
          </el-radio-group>
          <el-checkbox-group
            class="radio-group-box"
            v-if="item.qtype == '多选'"
            v-model="item.checkList"
            disabled="disabled"
          >
            <div
              class="radio_box"
              v-for="(item, index) in item.tiList"
              :key="index"
            >
              <el-checkbox :label="item.cred" v-if="item.content"
                >{{ item.cred }} {{ item.content }}</el-checkbox
              >
            </div>
          </el-checkbox-group>
          <el-radio-group
            v-model="item.daan"
            class="radio-group-box"
            v-if="item.qtype == '判断'"
            disabled="disabled"
          >
            <div class="radio_box">
              <el-radio label="正确">正确</el-radio>
            </div>
            <div class="radio_box">
              <el-radio label="错误">错误</el-radio>
            </div>
          </el-radio-group>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { questionsearch } from "@/api/admin.js";
import { getsubject_id } from "@/utils/auth";
export default {
  data() {
    return {
      list: [],
      keyword: "",
      loading: false,
    };
  },
  methods: {
    search() {
      if (this.keyword == "") return this.$message.error("关键词不能为空");
      this.loading = true;
      this.list = [];
      questionsearch({
        keyword: this.keyword,
        subjectid: getsubject_id(),
      }).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          res.data.list.map((item, index) => {
            item.tixu = index + 1;
            this.list.push(this.funChangeTi(item));
          });
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    funChangeTi(item) {
      let Arr = [];
      Arr.push(
        {
          cred: "A",
          content: item.a,
          content_img: item.a_img,
        },
        {
          cred: "B",
          content: item.b,
          content_img: item.b_img,
        },
        {
          cred: "C",
          content: item.c,
          content_img: item.c_img,
        },
        {
          cred: "D",
          content: item.d,
          content_img: item.d_img,
        },
        {
          cred: "E",
          content: item.e,
          content_img: item.e_img,
        },
        {
          cred: "F",
          content: item.f,
          content_img: item.f_img,
        }
      );
      return {
        name: item.tixu,
        stem: item.stem,
        tiList: Arr,
        answer: item.answer,
        daan: item.answer,
        checkList: item.answer.split(""),
        analysis: item.analysis,
        id: item.id,
        qtype: item.qtype,
      };
    },
  },
};
</script>

<style lang="scss" scoped>
@import "~@/styles/utis.scss";
.app-container {
  height: calc(100vh - 50px) !important;
}
.backgroundClass {
  height: 100%;
}
.tabs {
  height: calc(100% - 45px);
}
::v-deep {
  .el-radio__input.is-disabled + span.el-radio__label {
    color: #333;
  }
  .el-radio__input.is-disabled .el-radio__inner {
    border-color: #dcdfe6;
    background-color: #ffffff;
    &::after {
      background-color: #ffffff;
    }
  }
  .el-radio__input.is-disabled.is-checked .el-radio__inner {
    background-color: #1890ff;
    border-color: #1890ff;
  }
  .el-input-group__append {
    background-color: #1890ff;
    border: none;
    color: #fff;
  }
}
.radio-group-box {
  padding: 0 20px;
}
.radio_box {
  font-size: 20px;
  padding-bottom: 16px;
  ::v-deep {
    .el-radio__label,
    .el-checkbox__label {
      font-size: 20px !important;
      word-break: break-all !important;
      white-space: normal !important;
    }
    .el-radio__inner {
      width: 20px;
      height: 20px;
      &::after {
        width: 8px;
        height: 8px;
      }
    }
    .el-radio__input {
      margin-top: -5px;
    }
    .el-checkbox__input.is-disabled + span.el-checkbox__label {
      color: #333;
    }
    .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
      background-color: #1890ff !important;
      border-color: #1890ff !important;
      &::after {
        border-color: #ffffff !important;
      }
    }
  }
}
</style>
